﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net.Security;
using System.Security.Authentication;
using Tools.Debugging;

namespace repliback4.Net.ClientSide {
    public class ClientConnection : AsyncConnection {
        public ClientConnection ( TcpClient client ) : base( client ) { }


        public Boolean SwitchToSecure ( ) {

            this.sslStream = new SslStream( this.netStream );

            try {
                this.sslStream.AuthenticateAsClient( "" );
                this.stream = this.sslStream;
                return true;
            } catch ( AuthenticationException e ) {
                Logger.Debug( this, "AuthenticationException: [{0}] - [{1}]", e.Message, ( e.InnerException != null ? e.InnerException.Message : "-" ) );
            } catch ( Exception e ) {
                Logger.Debug( this, "Exception: [{0}]", e.Message );
            }
            return false;
        }
    }
}
